<template>
  <div>
    <table>
      <tr>
        <td><el-input v-model="name" placeholder="请输入内容"></el-input></td>

        <td><el-button type="primary" @click="show">查询</el-button></td>
        <td>
          <el-button type="success" @click="dialogVisible = true"
            >添加</el-button
          >
          <el-button type="success">导入</el-button>
          <el-button type="success">导出</el-button>
        </td>
        <td>
          <el-button type="warning" @click="upd">编辑</el-button>
        </td>
        <el-button type="danger" @click="del">删除</el-button>
      </tr>
    </table>

    <template>
      <el-table
        :data="tableData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="Process_Name" label="工序名称">
        </el-table-column>
        <el-table-column prop="Unit_Name" label="报工单位"> </el-table-column>
        <el-table-column prop="Pid_Name" label="产品名称"> </el-table-column>
        <el-table-column
          prop="Performance_based_pay_Money"
          label="工资单价(元)"
        >
        </el-table-column>
        <el-table-column prop="hour" label="标准工时(小时)"> </el-table-column>
        <el-table-column prop="minute" label="标准工时(分钟)">
        </el-table-column>
        <el-table-column prop="second" label="标准工时(秒)"> </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageIndex"
        :page-sizes="[1, 3, 5, 7]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.totalCount"
      >
      </el-pagination>
      <!-- 添加 -->
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <span>
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="工序">
              <el-select
                v-model="form.process_Id"
                clearable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in ProcessData"
                  :key="item.Process_Id"
                  :label="item.Process_Name"
                  :value="item.Process_Id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工艺">
              <el-select v-model="form.pid" clearable placeholder="请选择">
                <el-option
                  v-for="item in ProductsData"
                  :key="item.PId"
                  :label="item.PName"
                  :value="item.PId"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="单位">
              <el-select v-model="form.unit_Id" clearable placeholder="请选择">
                <el-option
                  v-for="item in unitData"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工资单价(元)">
              <el-input v-model="form.price"></el-input>
            </el-form-item>
            <el-form-item label="标准效率">
              <el-input-number
                v-model="form.standard"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="小时">
              <el-input-number
                v-model="form.hours"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="分钟">
              <el-input-number
                v-model="form.minutes"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="秒">
              <el-input-number
                v-model="form.seconds"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="Add">添加</el-button>
              <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
          </el-form>
        </span>
      </el-dialog>
      <!-- 编辑 -->
      <el-dialog title="提示" :visible.sync="dialogVisible111" width="30%">
        <span>
          <el-form ref="form" :model="form1" label-width="80px">
            <el-form-item label="工序">
              <el-select
                v-model="form1.Process_Id"
                clearable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in ProcessData"
                  :key="item.Process_Id"
                  :label="item.Process_Name"
                  :value="item.Process_Id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工艺">
              <el-select v-model="form1.Pid" clearable placeholder="请选择">
                <el-option
                  v-for="item in ProductsData"
                  :key="item.PId"
                  :label="item.PName"
                  :value="item.PId"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="单位">
              <el-select v-model="form1.unit_Id" clearable placeholder="请选择">
                <el-option
                  v-for="item in unitData"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工资单价(元)">
              <el-input v-model="form1.Price"></el-input>
            </el-form-item>
            <el-form-item label="标准效率">
              <el-input v-model="form1.standard"></el-input>
            </el-form-item>
            <el-form-item label="小时">
              <el-input-number
                v-model="form.hours"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="分钟">
              <el-input-number
                v-model="form1.minutes"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="秒">
              <el-input-number
                v-model="form1.seconds"
                controls-position="right"
                :min="1"
                :max="10"
              ></el-input-number>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="update">修改</el-button>
              <el-button @click="dialogVisible111 = false">取消</el-button>
            </el-form-item>
          </el-form>
        </span>
      </el-dialog>
    </template>
  </div>
</template>
<script>
export default {
  data() {
    return {
      multipleSelection: [],
      form: {
        creatorId: 0,
        createDate: "2023-12-11T13:02:37.450Z",
        updator: 0,
        updateDate: "2023-12-11T13:02:37.450Z",
        isDel: false,
        disposition_Id: 0,
        process_Id: 0 || null,
        unit_Id: 0 || null,
        pid: 0 || null,
        standard: "",
        price: "",
        hours: "",
        minutes: "",
        seconds: "",
      },
      form1: {
        disposition_Id: "",
        Process_Id: 0 || null,
        unit_Id: 0 || null,
        Pid: 0 || null,
        standard: "",
        Price: "",
        hours: "",
        minutes: "",
        seconds: "",
        CreatorId: "",
        CreateDate: "",
        Updator: 0,
        UpdateDate: "",
        IsDel: false,
      },
      dialogVisible: false,
      dialogVisible111: false,
      name: "",

      //分页
      page: {
        pageIndex: 1,
        pageSize: 5,
        totalCount: 0,
        pagerCount: 0,
      },
      //工序
      ProcessData: [],
      //单位
      unitData: [],
      ProductsData: [],
    };
  },
  methods: {
    //列表显示
    show() {
      this.axios
        .get(
          "http://localhost:5255/api/Disposition/GetDispositions",

          {
            params: {
              name: this.name,
              pageIndex: this.page.pageIndex,
              pageSize: this.page.pageSize,
            },
          }
        )
        .then((res) => {
          this.tableData = res.data.data;
          this.page.totalCount = res.data.totalCount;
          this.page.pagerCount = res.data.pagerCount;
        });
    },
    //分页
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.show();
    },
    //分页
    handleCurrentChange(val) {
      this.page.pageIndex = val;
      this.show();
    },
    //添加
    Add() {
      this.axios
        .post("http://localhost:5255/api/Disposition/AddDisposition", this.form)
        .then((res) => {
          if (res.data > 0) {
            this.$message.success("添加成功");
            this.dialogVisible = false;
            this.show();
          }
        });
    },
    //工序
    ProcessShows() {
      this.axios
        .get("http://localhost:5255/api/Disposition/GetProcessShows")
        .then((res) => {
          this.ProcessData = res.data;
        });
    },
    //工艺
    GetProducts() {
      this.axios
        .get("http://localhost:5255/api/Disposition/GetProducts")
        .then((res) => {
          this.ProductsData = res.data;
        });
    },
    getUnit() {
      this.axios
        .get("http://localhost:5255/api/Disposition/GetUnits")
        .then((res) => {
          this.unitData = res.data;
        });
    },
    //编辑
    upd() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          message: "请选择要编辑的数据",
          type: "warning",
        });
        return;
      }
      if (!(this.multipleSelection.length == 1)) {
        this.$message({
          message: "只能选择一行编辑的数据",
          type: "warning",
        });
        return;
      }
      this.dialogVisible111 = true;
      let ps = [];
      this.multipleSelection.forEach((e) => {
        ps.push(e.Performance_based_pay_Id);
      });
      this.axios
        .get("http://localhost:5255/api/Disposition/disposition?id=" + ps)
        .then((res) => {
          this.form1 = res.data;
        });
    },
    update() {
      this.axios
        .put(
          "http://localhost:5255/api/Disposition/updateDisposition",

          this.form1
        )
        .then((res) => {
          if (res.data == 1) {
            this.$message.success("修改成功");
            this.show();
            this.dialogVisible111 = false;
          }
        });
    },
    //批量删除
    del() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          message: "请选择要删除的数据",
          type: "warning",
        });
        return;
      }
      let ps = [];
      this.multipleSelection.forEach((e) => {
        ps.push(e.Performance_based_pay_Id);
      });

      this.axios
        .put("http://localhost:5255/api/Disposition/plDelte?ids=" + ps)
        .then((res) => {
          if (res.data == 1) {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.show();
          } else {
            this.$message({
              message: "删除失败",
              type: "error",
            });
          }
        });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
  created() {
    this.show();
    this.ProcessShows();
    this.GetProducts();
    this.getUnit();
  },
};
</script>
<style>
</style>